package com.fling.tutorial;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import com.fling.Constants;
import com.fling.Locator;
import com.fling.entity.Entity;
import com.fling.observer.Event;
import com.fling.observer.Observer;
import com.fling.observer.Subject;

public class TutorialManager implements Constants, Observer{

	private boolean completed;
	private TutorialState state;
	private BitmapFont fontSmall;
	private NinePatch patch;
	
	public TutorialManager(Subject sub){
		state=new StartState(this, sub);
		patch = new NinePatch(new Texture(Gdx.files.internal("data/art/textBack.png")));
		completed=Locator.isTutorialCompleted();
		FileHandle fontFile = Gdx.files.internal(FONT);
	    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
	    FreeTypeFontParameter param=new FreeTypeFontParameter();
	    param.size=(int) (44/UI_SCALE);
	    fontSmall = generator.generateFont(param);
	    generator.dispose();
	}
	
	public void update(float delta){
		state.update(delta);
	}
	
	public void render(SpriteBatch sb){
		sb.begin();
		state.render(sb, patch, fontSmall);
		sb.end();
	}
	
	public void registerInput(INPUT input){
		state.registerInput(input);
	}
	
	public void changeState(TutorialState ts){
		state=ts;
	}

	@Override
	public void onNotify(Entity entity, Event event) {
		// TODO Auto-generated method stub
		
	}
	
	public void restart(){
		
	}

	public void jumpRight() {
        state.registerInput(INPUT.JUMP_RIGHT);
    }

    public void jumpDown() {
        state.registerInput(INPUT.JUMP_DOWN);
    }

    public void jumpUp() {
        state.registerInput(INPUT.JUMP_UP);
    }

    public void jumpLeft() {
        state.registerInput(INPUT.JUMP_LEFT);
    }

    public void climb() {
        state.registerInput(INPUT.CLIMB);
    }

    public void fall() {
        state.registerInput(INPUT.FALL);
    }

	public boolean isCompleted() {
		return completed;
	}

	public void setCompleted(boolean completed) {
		this.completed = completed;
	}

	public void reset(Subject sub) {
		state=new StartState(this, sub);
		
	}
    
    
}
